package com.atguigu.eduservice.controller.front;

import com.atguigu.eduservice.entity.EduCourse;
import com.atguigu.eduservice.entity.EduTeacher;
import com.atguigu.eduservice.service.EduCourseService;
import com.atguigu.eduservice.service.EduTeacherService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.atguigu.commonutils.R;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @Author: Cyrus
 * @CreateDate: 2020/12/16
 */

@RestController
@RequestMapping("/eduservice/teacherfront")
public class TeacherFrontController {
    @Autowired
    private EduTeacherService teacherService;

    @Autowired
    private EduCourseService eduCourseService;

    @PostMapping("getTeacherFrontList/{current}/{limit}")
    public R getTeacherFrontList(@PathVariable long current, @PathVariable long limit) {
        Page<EduTeacher> teacherPage = new Page<>(current, limit);
        Map<String, Object> map = teacherService.pageListWeb(teacherPage);
        //返回分页的所有数据
        return R.ok().data(map);
    }

    @GetMapping("getTeacher/{id}")
    public R getTeacher(@PathVariable long id) {
        EduTeacher teacher = teacherService.getById(id);
        List<EduCourse> list = eduCourseService.list(new QueryWrapper<EduCourse>().lambda().eq(EduCourse::getTeacherId, id));
        //返回分页的所有数据
        return R.ok().data("teacher",teacher).data("courseList",list);
    }
}
